
$(document).ready(function() {
	initTable();
	
	$('#search').on('click',function(){
		initTable();
	});
});

var table = new Table();
var initTable =function(){
	//筛选条件
	var orderNo = $('#orderNo').val();
	var sql ='?orderState=1';
	if(orderNo!=null&& orderNo!=''){
		sql += '&orderNo='+orderNo;
	}
	//表格加载的字段
    var cloumns = [
		    {'data': 'id','render': function (data) { return '<input type="checkbox" data-id="' + data + '" name="">';}},
		    {'data': 'order_no'},
		    {'data': 'picture','render': function (data) {return '<img style="max-width: 40px; max-height: 40px;"  src= "'+basePath+'/'+data+'" />';}},
		    {'data': 'nick_name'},
		    {'data': 'amount_money'},
		    {'data': 'receive_address'},
		    {'data': 'receive_address_detail'},
		    {'data': 'update_name'},
		    {'data': 'update_date'},
		    {'data': 'id','render':function(data,type,full){
		    	var url =basePath+"/order/toEditOrder?id="+data;
		    	var titles = '详情';
		    	var btn ='<a title="详情" href="javascript:;" onclick="toEdit(\''+titles+'\',\''+url+'\',\''+type+'\')" class="btn btn-primary  radius size-MINI" style="margin-right:10px;" >'+titles+'</a>';   
		    	var title = '发货';
		    	btn +='<a title="'+title+'" href="javascript:;" onclick="ship(\''+data+'\')" class="btn btn-success radius size-MINI" style="margin-right:10px;" >'+title+'</a>';   
		    	return table.delBtn(data)+btn;
		    	}}
		  ];
	//设置URL和加载的字段
    table.setting(basePath+"/order/getOrderList"+sql,basePath+"/order/delOrder",cloumns);
	//调用表格分页
    table.tablePage();
}


//发货窗口
function ship(id){
	  var  html =  '<form class="form-horizontal" style = "margin-top:5%;">'+
	                                '<div class="row cl" style = "margin-right: 0px;">'+
					    			'<label class="form-label col-xs-3 col-sm-4"><span class="c-red">*</span>快递公司：</label>'+
					    			'<div class="formControls col-xs-5 col-sm-6">'+
					    				'<input type="text" class="input-text valid" value="" placeholder="" id="expressCompany">'+
					    			'</div>'+
					    			'</div>'+
					    			'<div class="row cl" style = "margin-right: 0px;margin-top:5%;">'+
					    			'<label class="form-label col-xs-3 col-sm-4"><span class="c-red">*</span>快递单号：</label>'+
					    			'<div class="formControls col-xs-5 col-sm-6">'+
					    				'<input type="text" class="input-text valid" value="" placeholder="" id="expressNum">'+
					    			'</div>'+
					    			'</div>'+
							'</form>';
					
		 layer.open({
			type: 1,
			skin: 'layui-layer-molv',
			title: "发货信息",
			area: ['500px', '250px'],
			shadeClose: false,
			content: html,
			btn: ['确认','取消'],
			btn1: function (index) {
				
				var expressCompany = $('#expressCompany').val(),expressNum = $('#expressNum').val();
				
				
				if(expressCompany==""){
					layer.msg("请输入快递公司");
					return false;
				}
				if(expressNum==""){
					layer.msg("请输入快递单号");
					return false;
				}
				 
				 var data = {
						 'express_company':expressCompany,
						 'express_num':expressNum,
						 'order_state':'2',
						 'id':id
				 }
				 
				$.ajax({
					type: "POST",
				    url: basePath + "/order/editOrder",
				    data: data,
				    dataType: "json",
				    success: function(r){
						if(r.code == 0){
							layer.close(index);
							initTable();
							layer.msg('发货成功');
						}else{
							layer.msg(r.msg);
						}
					}
				});  
		    }
		}); 
	}
